{extend name="layout:base" /}

{block name="style"}
<style>
    .layui-table-cell{line-height: 40px;height: 40px;}
</style>
{/block}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="test-table-reload-btn" style="margin-bottom: 10px;">
                <div class="layui-inline">
                    <select name="order" id="order" lay-filter="order">
                        <option value="">排序规则</option>
                        <option value="inTime_asc">下单时间升序</option>
                        <option value="inTime_desc">下单时间降序</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="kfID" id="kfID" lay-filter="kfID">
                        <option value="">查找客服</option>
                        {volist name="kfList" id="vo"}
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="oID" id="oID" lay-filter="oID">
                        <option value="">查找技术或者编辑</option>
                        {volist name="techList" id="vo"}
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-inline">
                    <input class="layui-input" name="keywords" id="keywords" autocomplete="off" placeholder="签单人/网站名/网站ID/域名/">
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>

        </div>
        <div class="layui-card-body">
            <table id="tbList" class="layui-table" lay-filter="tbList" ></table>
            <script type="text/html" id="toolbarDemo">

            </script>
            <script type="text/html" id="state">
                <div class="layui-progress layui-progress-big" lay-showpercent="yes">
                    <h3>{{d.progress}}%</h3>
                    <div class="layui-progress-bar" lay-percent="{{d.progress}}" style="width: {{d.progress}}%;"><span class="layui-progress-text">{{d.progress}}</span></div>
                    {{d.recordName}}-{{d.recordTxt}}-{{d.recordTime}}
                </div>

            </script>
            <script type="text/html" id="op">


                {{#  if({$Think.session.admin.levelNum}==50){ }}
                <a class="layui-btn layui-btn-xs" lay-event="turn" lay-tips="分配">分</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" lay-tips="删除该网站？" >删</a>
                {{#  } }}


                {{#  if( {$my.webPower}===1 ){ }}
                <a class="layui-btn layui-btn-xs" lay-event="turn" lay-tips="分配技术编辑">分</a>
                {{#  } }}

                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-href="{:url(('show'))}?id={{d.id}}" lay-tips="查看网站详情" lay-text="{{d.name}}-详情" >详</a>

                {{#  if(d.editID == {$Think.session.admin.id}){ }}
                    <a class="layui-btn layui-btn-xs" lay-href="{:url(('end'))}?id={{d.id}}" lay-tips="网站上线" lay-text="{{d.name}}-上线">上线</a>
                {{#  } }}
            </script>
        </div>
    </div>
</div>

{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'util','form'], function () {

        //表格
        var $ = layui.$,form = layui.form,layer = layui.layer,table = layui.table;
        table.render({
            elem: '#tbList',
            url: "{:url('getList')}",
            toolbar: '#toolbarDemo',
            cellMinWidth: 80,
            cols: [[
                {field: 'id', fixed: 'left', title: 'ID',width:60, sort: false},
                {field: 'name',fixed: 'left',title: '客户'},
                // {field: 'signTime',title: '签单时间',width:105},
                {field: 'kfName',title: '客服',width:80},
                {field: 'inTime',title: '下单时间',width:120},
                {field: 'typeName',title: '下单类型',width:100},
                {field: 'editName',width:80, title: '编辑',sort: true},
                {field: 'techName',width:80, title: '技术',sort: true},
                {field: 'techTxt', title: '框架备注',sort: true, edit: 'text'},
                // {field: 'special', title: '特殊要求',width:130},
                {field: 'state', title: '网站进度',templet: '#state'},
                {field: 'sort',width:80, title: '排序',sort: true, edit: 'text'},
                {fixed: 'right', title: '操作',width:130, toolbar: '#op'}
            ]],
            done: function (res, curr, count){
                var data=res.data;
                for (var i=0;i<data.length;i++){
                    if(data[i]['dayGo']>7){
                        $('[lay-id=tbList] tbody tr[data-index='+[i]+']').css({'background-color': "#ffb3b3"});
                    }else if(data[i]['dayGo']>10){
                        $('[lay-id=tbList] tbody tr[data-index='+[i]+']').css({'background-color': "#ff0000",'color':"#fff"});
                    }
                }

            },
            page: true,
            limit:10
        });

        // 监听工具条
        table.on('tool(tbList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var url = "{:url('edit')}?id=" + data['id'];
                var index = layer.open({
                    type: 2,
                    title: '修改站点',
                    area: ['90%', '90%'],
                    shade: 0,
                    maxmin: true,
                    content: url,
                    zIndex: layer.zIndex
                });
            }else  if (obj.event === 'turn') {
                var url = "{:url('turn')}?id=" + data['id'];
                var index = layer.open({
                    type: 2,
                    title: '分配',
                    area: ['90%', '90%'],
                    shade: 0,
                    maxmin: true,
                    content: url,
                    zIndex: layer.zIndex
                });
            }else  if (obj.event === 'del') {
                layer.confirm('确定删除', {icon: 3, title: '提示'}, function (index) {
                    $.post("{:url('del')}", {id: data['id']}, function (result) {
                        if (result['code'] == 0) {
                            layer.msg(result['msg'], {icon: 1, time: 2000}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(result['msg'], {icon: 3, time: 3000});
                        }
                    });
                });
            }else  if (obj.event === 'getData') {
                layer.confirm('确定拿到资料了么？', {icon: 3, title: '提示'}, function (index) {
                    $.post("{:url('setDataGetTime')}", {id: data['id'] }, function (result) {
                        if (result['code'] == 0) {
                            layer.msg(result['msg'], {icon: 1, time: 2000}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(result['msg'], {icon: 3, time: 3000});
                        }
                    });
                });
            }
        });

        //监听单元格编辑
        table.on('edit(tbList)', function (obj) {
            var value = obj.value; //得到修改后的值
            var data = obj.data; //得到所在行所有键值
            var field = obj.field; //得到字段
            layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为：' + value);

            $.post("{:url('edit')}", {id: data.id, techTxt: value}, function (result) {
                if (result['code'] == 0) {
                    layer.msg(result['msg'], {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(result['msg'], {icon: 3, time: 3000});
                }
            });
        });


        //监听推荐
        form.on('switch(state)', function (data) {
            //停用
            var id=data.value;
            layer.open({
                content: '确认修改该站点状态?'
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                    $.post("{:url('state_web')}",{id:id,'state': data.elem.checked ? 1 : 3}, function (result) {
                        if (result['code'] == 0) {
                            location.reload();
                        } else {
                            layer.msg(result['msg'], {icon: 3, time: 3000});
                        }
                    });
                    form.render();
                    layer.close(index);
                }
                ,btn2: function(index, layero){
                    layer.close(index);
                }
            });
            return false;
        });


        //操作
        var $ = layui.$, active = {
            add: function (obj) {
                var index = layer.open({
                    type: 2,
                    title: '添加站点',
                    area: ['90%', '90%'],
                    shade: 0,
                    maxmin: true,
                    content: "{:url('add')}",
                    zIndex: layer.zIndex
                });
                layer.full(index);
            },
            reload: function(){
                var order=$('#order').val();
                var keywords=$('#keywords').val();
                var kfID=$('#kfID').val();
                var oID=$('#oID').val();

                //执行重载
                table.reload('tbList', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        order: order
                        ,kfID: kfID
                        ,oID: oID
                        ,keywords: keywords
                    }
                });

            }
        };


        $('.test-table-reload-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
{/block}